{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 一、知识库构建(采用../../data/github_data数据)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ZHIPUAI_API_KEY\n",
      "DASHSCOPE_API_KEY\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from dotenv import dotenv_values\n",
    "env_variables = dotenv_values('.env')\n",
    "for var in env_variables:\n",
    "    print(var)\n",
    "    os.environ[var] = env_variables[var]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Calculating embeddings:   0%|          | 0/11 [00:00<?, ?it/s]"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Calculating embeddings: 100%|██████████| 11/11 [00:01<00:00,  5.94it/s]\n"
     ]
    }
   ],
   "source": [
    "from RAG.Embeddings import ZhipuEmbedding\n",
    "from RAG.VectorBase import VectorStore\n",
    "from RAG.utils import ReadFiles\n",
    "\n",
    "docs = ReadFiles('../../data/github_data').get_content(max_token_len=600, cover_content=150) # 获得data目录下的所有文件内容并分割\n",
    "vector = VectorStore(docs)\n",
    "embedding = ZhipuEmbedding() # 创建EmbeddingModel\n",
    "vector.get_vector(EmbeddingModel=embedding)\n",
    "vector.persist(path='../../storage/github_data') # 将向量和文档内容保存到storage目录下，下次再用就可以直接加载本地的数据库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "paddlenlp",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
